#include "SettingsDialog.hpp"
#include "ui_SettingsDialog.h"
#include "ExamWindow.hpp"

SettingsDialog::SettingsDialog(ExamConfig *c_, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SettingsDialog),
    cfg(c_)
{
    ui->setupUi(this);
    ui->mainFontSelect->setCurrentFont(c_->mainfont);
    int pt=c_->mainfont.pixelSize();
    ui->mainFontSize->setValue(pt>0?pt:12);
    ui->itemFontSelect->setCurrentFont(c_->itemfont);
    pt=c_->itemfont.pixelSize();
    ui->itemFontSize->setValue(pt>0?pt:12);
    connect(ui->buttonBox,SIGNAL(accepted()),this,SLOT(accept()));
    connect(ui->buttonBox,SIGNAL(rejected()),this,SLOT(reject()));
}

SettingsDialog::~SettingsDialog()
{
    delete ui;
}

void SettingsDialog::accept()
{
    cfg->mainfont=ui->mainFontSelect->currentFont();
    cfg->mainfont.setPixelSize(ui->mainFontSize->value());
    cfg->itemfont=ui->itemFontSelect->currentFont();
    cfg->itemfont.setPixelSize(ui->itemFontSize->value());
    QDialog::accept();
}
